// createRouter: 用来创建rouer实例化对象
// createWebHashHistory 用来创建哈希模式的路由实例化对象
import { createRouter, createWebHashHistory } from 'vue-router'
import Layout from '@/views/Layout'
import Login from '@/views/Login'
import Home from '@/views/Home'
import Category from '@/views/Category'
import Good from '@/views/Good'
// 路由规则数组: path配置项和component配置项
const routes = [
  {
    path: '/',
    component: Layout,
    children: [
      {
        path: '',
        component: Home
      },
      {
        path: 'category/:id',
        component: Category
      },
      {
        path: 'good/:id',
        component: Good
      }
    ]
  },
  {
    path: '/login',
    component: Login
  }
]

// 创建路由实例化对象
const router = createRouter({
  // 使用hash哈希方式实现路由
  history: createWebHashHistory(),
  // 配置路由规则
  routes
})

// 导出给main.js使用
export default router
